import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import electronRenderer from 'vite-plugin-electron-renderer'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    electron([
      {
        entry: 'src/electron/main/index.ts',
        vite: {
          build: {
            outDir: 'dist-electron/main'
          },
          plugins: [],
          // 确保开发环境变量正确传递
          define: {
            'process.env.VITE_DEV_SERVER_URL': process.env.VITE_DEV_SERVER_URL ? JSON.stringify(process.env.VITE_DEV_SERVER_URL) : 'undefined'
          }
        }
      },
      {
        entry: 'src/electron/preload/index.ts',
        vite: {
          build: {
            outDir: 'dist-electron/preload'
          },
          plugins: []
        }
      }
    ]),
    electronRenderer()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  server: {
    port: 3000,
    host: 'localhost',
    open: false,
    strictPort: true,
    cors: true,
    hmr: {
      port: 3000
    }
  },
  build: {
    outDir: 'dist'
  }
})